package com.union.core.doc.service;

import java.util.List;

import org.apache.log4j.Logger;

import com.union.core.doc.dao.OfficialDocDao;
import com.union.core.doc.dao.impl.OfficialDocDaoImpl;
import com.union.core.doc.model.DocAttachment;
import com.union.core.doc.model.DocTemplate;
import com.union.core.doc.model.OfficialDoc;
import com.union.core.doc.model.OfficialDocOrg;
import com.union.core.doc.model.SealSignature;
import com.union.core.doc.pojo.OfficialDocOrgPojo;
import com.union.core.doc.pojo.OfficialDocPojo;

public class OfficialDocManagerService {
	private static Logger log = Logger.getLogger(OfficialDocManagerService.class.getName());
	private OfficialDocDao officialDocDao;
	
	public OfficialDocManagerService(){
		officialDocDao = new OfficialDocDaoImpl();
	}
	
	public int queryCount(OfficialDocPojo officialDocPojo,int creatId){
		int count = officialDocDao.queryCount(officialDocPojo, creatId);
		return count;
	}
	
	/**
	 * 查询机构信息列表
	 */
	public List<OfficialDoc> query(OfficialDocPojo officialDocPojo, int start,int pageSize,int creatId){
		List<OfficialDoc> officialDocList = officialDocDao.query(officialDocPojo, start, pageSize, creatId);
		return officialDocList;
	}
	
	public void Success(OfficialDoc officialDoc){
			officialDocDao.Success(officialDoc);
			log.info("PLAT：下发公文" +officialDoc.getId()+","+officialDoc.getTitle());
	}
	
	public void add(OfficialDoc officialDoc){
		officialDocDao.add(officialDoc);
		log.info("PLAT: 添加公文: "+officialDoc.getId()+","+officialDoc.getTitle());
	}

	public OfficialDoc query(long lid){
		OfficialDoc officialDoc = officialDocDao.query(lid);
		log.info("PLAT:  查询单个公文: id="+lid);
		return officialDoc;
	}

	public OfficialDocOrg queryOrg(long lid){
		OfficialDocOrg officialDocOrg = officialDocDao.queryOrg(lid);
		return officialDocOrg;
	}

	public void edit(OfficialDoc officialDoc){
		officialDocDao.edit(officialDoc);
		log.info("PLAT: 修改公文: "+officialDoc.getId()+","+officialDoc.getTitle());
	}

	public void edit(OfficialDocOrg officialDocOrg){
		officialDocDao.edit(officialDocOrg);
	}
	
	public void add(OfficialDocOrg officialDocOrg){
		officialDocDao.add(officialDocOrg);
		log.info("PLAT: 添加公文接收单位关系: "+officialDocOrg.getId());
	}
	
	public int queryDocOrgCount(OfficialDocOrgPojo officialDocOrgPojo){
		int count = officialDocDao.queryDocOrgCount(officialDocOrgPojo);
		return count;
	}
	
	public List<OfficialDocOrg> queryDocOrg(OfficialDocOrgPojo officialDocOrgPojo, int start,int pageSize){
		List<OfficialDocOrg> officialDocOrgList = officialDocDao.queryDocOrg(officialDocOrgPojo, start, pageSize);
		return officialDocOrgList;
	}
	
	public int queryDocOrgForStatusCount(OfficialDocOrgPojo officialDocOrgPojo){
		int count = officialDocDao.queryDocOrgForStatusCount(officialDocOrgPojo);
		return count;
	}
	
	public List<OfficialDocOrg> queryDocOrgForStatus(OfficialDocOrgPojo officialDocOrgPojo, int start,int pageSize){
		List<OfficialDocOrg> officialDocOrgList = officialDocDao.queryDocOrgForStatus(officialDocOrgPojo, start, pageSize);
		return officialDocOrgList;
	}
	
	public Boolean delete(long id){
		return officialDocDao.delete(id);
	}
	
	public int querySealCount(SealSignature sealSignature){
		int count = officialDocDao.querySealCount(sealSignature);
		return count;
	}
	
	public List<SealSignature> querySeal(SealSignature sealSignature, int start,int pageSize){
		List<SealSignature> sealSignatureList = officialDocDao.querySeal(sealSignature, start, pageSize);
		return sealSignatureList;
	}
	
	public SealSignature querySeal(long lid){
		return officialDocDao.querySeal(lid);
	}
	
	public void add(SealSignature sealSignature){
		officialDocDao.add(sealSignature);
	}
	
	public void edit(SealSignature sealSignature){
		officialDocDao.edit(sealSignature);
	}
	
	public Boolean deleteSeal(long id){
		return officialDocDao.deleteSeal(id);
	}
	
	public void add(List<DocAttachment> daList){
		if(daList != null && daList.size() > 0){
			officialDocDao.add(daList);
		}
	}
	
	/**
	 * 根据公文id查询归属该公文的附件
	 * @param doc_id
	 * @return
	 */
	public List<DocAttachment> queryDocAttach(long doc_id){
		return officialDocDao.queryDocAttach(doc_id);
	}

	public DocAttachment queryDAById(long lid){
		DocAttachment da = officialDocDao.queryDAById(lid);
		return da;
	}
	
	public Boolean deleteDocAttach(long id){
		return officialDocDao.deleteDocAttach(id);
	}
	
	public int queryTemplateCount(DocTemplate docTemplate){
		int count = officialDocDao.queryTemplateCount(docTemplate);
		return count;
	}
	
	public List<DocTemplate> queryTemplate(DocTemplate docTemplate, int start,int pageSize){
		List<DocTemplate> docTemplateList = officialDocDao.queryTemplate(docTemplate, start, pageSize);
		return docTemplateList;
	}
	
	public DocTemplate queryTemplate(long lid){
		return officialDocDao.queryTemplate(lid);
	}
	
	public void add(DocTemplate docTemplate){
		officialDocDao.add(docTemplate);
	}
	
	public void edit(DocTemplate docTemplate){
		officialDocDao.edit(docTemplate);
	}
	
	public Boolean deleteTemplate(long id){
		return officialDocDao.deleteTemplate(id);
	}
}
